package br.eck.model.base.effects;

import java.awt.Color;
import java.awt.Font;

import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.UnicodeFont;
import org.newdawn.slick.font.effects.ColorEffect;

import br.eck.config.Config;
import br.eck.model.base.Effect;

public class TextBasedEffect implements Effect {

    private String text;
    private int time;

    private int timePassed;

    UnicodeFont font;

    public TextBasedEffect(String text, int time) {
        this.text = text;
        this.time = time;
    }

    public Effect cloneThis() {
        try {
            return (Effect)super.clone();
        } catch (CloneNotSupportedException e) {
            return null;
        }
    }

    public void draw(Graphics g) throws SlickException {
        font.drawString((Config.PLAYABLE_AREA - font.getWidth(text)) / 2, Config.GAME_HEIGHT / 2, text);
        font.loadGlyphs();
    }

    public boolean hasEnded() {
        return timePassed >= time;
    }

    @SuppressWarnings("unchecked")
    public void start() {
        timePassed = 0;
        font = new UnicodeFont(new Font("Arial Black", Font.BOLD, 30));
        font.getEffects().add(new ColorEffect(Color.white));
    }

    public void update(int timePassed) {
        this.timePassed += timePassed;
    }

}
